num_temporaries = 0
num_labels = 0


def getNewTemp():
      global num_temporaries
      #Returns a new temporary named _T<num>
      temp = "_T00"
      temp[2] = num_temporaries / 10 + '0'
      temp[3] = num_temporaries % 10 + '0'
      num_temporaries = num_temporaries + 1
      return temp

def getNewLabel():
      global num_labels
      #Returns a new temporary named _T<num>
      temp = "_L00"
      temp[2] = num_labels / 10 + '0'
      temp[3] = num_labels % 10 + '0'
      num_labels = num_labels + 1
      return temp

def replicate(str1):
      if str1!= None:
	    temp = str1
      else:
	    temp = ""
      #free(str1);
      return temp
      
      
def append(str1, str2):
	return str1 + str2


def gen(instr, reg, addr):
      buf = addr
      t = instr + " " + reg + "," + buf
      return t

def toAddr(offset):
      if offset < 100 :
	    temp = "---($sp)"
	    #offset = - offset;
	    temp [1] = (offset / 10) + '0'
	    temp [2] = (offset % 10) + '0'
	    return temp
      else:
	    temp = "----($sp)"
	    #offset = - offset;
	    temp [1] = (offset / 100) + '0'
	    temp [2] = ((offset % 100) / 10) + '0'
	    temp [3] = (offset % 10) + '0'
	    return temp

